const Router=require("koa-router");
const db=require("../database");
const router=new Router();;
router.get("/user",async function(ctx){
     let user={
        name:"tom",
        age:20,
        type:"get"
     };
     ctx.body=JSON.stringify(user);
});

router.post("/user",async function(ctx){
    let user={
       name:"tom",
       age:20,
       type:"post"
    };
    ctx.body=JSON.stringify(user);
});

router.put("/user",async function(ctx){
    let user={
       name:"tom",
       age:20,
       type:"put"
    };
    ctx.body=JSON.stringify(user);
});
router.get("/serviceError",async function(){
    sddssfdsdfsdfs
    ctx.body="啊哈哈哈";
});
const sleep=function(){
    let p=new Promise(function(resolve,reject){
        setTimeout(resolve,3000);
    });
    return p;
};
router.get("/userAsync",async function(ctx){
    await sleep();//请求在该位置等待3s，至少等待3s
    let user={
        name:"tom",
        age:20,
        type:"get"
     };
     ctx.body=JSON.stringify(user);
});
router.get("/class",async function(ctx){
    let classData=db.findClassList();
    ctx.body=classData;
});



exports.ajaxRouter=router;